package com.worldwizards.smut.serialization;

import java.io.IOException;
import java.util.List;

public class SerializedObjectRecord extends ParseObject{
	SerializedClassRecord _classDescription;
	List<ValueRecord> _valuesList;

	public SerializedObjectRecord(SerializedObjectRoot root, BinaryParser parser, int newHandle,
			SerializedClassRecord cd) throws IOException, SerializationParsingException {
		super(newHandle);
		_classDescription = cd;
		if (!_classDescription.isExternalizable()){
			if (_classDescription.hasWriteMethod()){
				parseWriteClass(root, parser);
			}
			parseObjectAnnotation(parser);
		}
		parseValues(root, parser);
	}

	private void parseWriteClass(SerializedObjectRoot root, BinaryParser parser) throws IOException, SerializationParsingException {
		parseNoWriteClass(root, parser);
	}

	private void parseNoWriteClass(SerializedObjectRoot root, BinaryParser parser) throws IOException, SerializationParsingException {
		parseValues(root,parser);
	}



	private void parseValues(SerializedObjectRoot root, BinaryParser parser) throws IOException, SerializationParsingException {
		_valuesList = _classDescription.parseValues(root,parser);
	}



	private void parseObjectAnnotation(BinaryParser parser) {
		// TODO Auto-generated method stub
		
	}
 
	@Override
	protected void dumpDetails(String prefix) {
		System.out.println(prefix+"Serialized Object");
		System.out.print(prefix+"   Object Class:");
		_classDescription.dump(prefix+"   ");
		for(ValueRecord value: _valuesList){
			value.dump(prefix+"   ");
		}
	}

	
}
